package com.dnzx.service.impl;

import com.dnzx.dao.IParamDao;
import com.dnzx.model.ParamBO;
import com.dnzx.service.IParamService;
import org.dnzx.framework.page.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 参数管理Service实现类
 * @author ysb
 */
@Service
public class ParamServiceImpl implements IParamService {

    @Resource
    private IParamDao paramDao;

    @Override
    public void save(ParamBO paramBO) throws Exception {
        this.paramDao.save(paramBO);
    }

    @Override
    public void delete(Long id) throws Exception {
        this.paramDao.delete(id);
    }

    @Override
    public void update(ParamBO paramBO) throws Exception {
        this.paramDao.update(paramBO);
    }

    @Override
    public ParamBO get(Long id) {
        return this.paramDao.get(id);
    }

    @Override
	public ParamBO get(ParamBO paramBO) {
    	List<ParamBO> paramBOList = this.paramDao.queryList(paramBO);
    	if (paramBOList != null && paramBOList.size() > 0) {
    		return paramBOList.get(0);
    	}
		return null;
	}
    
    @Override
	public String get(String code) {
    	ParamBO paramBO = new ParamBO();
    	paramBO.setCode(code);
    	paramBO = this.get(paramBO);
		return paramBO.getParamValue();
	}

    @Override
    public List<ParamBO> queryList(ParamBO paramBO) {
        return this.paramDao.queryList(paramBO);
    }

    @Override
    public PageResult<List<ParamBO>> queryPage(ParamBO paramBO, PageResult<List<ParamBO>> pageResult) {
    	int totalRows = this.paramDao.queryCount(paramBO);
        pageResult.setTotalRows(totalRows);
        pageResult.setCurrentPage(paramBO.getCurrentPage());
        pageResult.setPageSize(paramBO.getPageSize());
		List<ParamBO> records = this.paramDao.queryPage(pageResult.getPageSize(), pageResult.getStartRow(), paramBO);
		pageResult.setT(records);
		return pageResult;
    }

}
